##############
# (*) Kaleidoscope
# By: Allan Spale
# June 2008

import sys

class KSColumnFactoryError(Exception):
    """
    Exception class for KSColumnFactory

    """
    B_UNKNOWN_EXCEPTION = True
    B_CLASS_EXCEPTION = False


    def __init__(self, u_message):
        self.__u_message = u_message
    def __str__(self):
        return repr(self.__u_message)

    @staticmethod
    def print_and_raise_error(u_message, b_unknown_exception):
        """
        Convenience method for printing and raising an error for this
        particular Exception subclass.

        """
        #sys.stderr.write(sys.exc_info())  # write initial error
        u_message = u'KSColumnFactory.py: ' + u_message
        sys.stderr.write(u_message + u'\n')

        if (b_unknown_exception):
            raise Exception(u_message)
        else:
            raise KSColumnFactoryError(u_message)


class KSColumnFactory(object):
    """
    In order to create a single point of creating KSColumn subclasses in a
    somewhat generic way, a factory class will be created. This will hopefully
    reduce the number of classes that need to be re-written for each datastore
    and motivate people to port their favorite datastores to Kaleidoscope by
    making it relatively tolerable.

    This class will be overridden in other classes to do the same thing for
    other datastores.

    """
    # Global column type (uniquely assign for each column factory)
    I_UNIQUE_COL_UNIQUE_VALS = 1
    I_UNIQUE_COL_DUPLICATE_VALS = 2
    I_DUPLICATE_COL = 3
    I_VIRTUAL_COL = 4


    def __init__(self, *args):
        raise NotImplementedError, \
            u'__init__ must be implemented in a subclass.'

    def create_column(self, i_column_type, *args):
        raise NotImplementedError, \
            u'create_column must be implemented in a subclass.'

    def delete_column_from_filesystem(self, u_column_filename):
        raise NotImplementedError, \
            u'delete_column_from_filesystem must be implemented in a subclass.'

    def new_ks_column_unique_unique_values(self, *args):
        raise NotImplementedError, \
            u'new_ks_column_unique_unique_values must be implemented ' \
            + u'in a subclass.'

    def new_ks_column_unique_duplicate_values(self, *args):
        raise NotImplementedError, \
            u'new_ks_column_unique_duplicate_values must be implemented ' \
            + u'in a subclass.'

    def new_ks_column_duplicate_duplicate_values(self, *args):
        raise NotImplementedError, \
            u'new_ks_column_duplicate_duplicate_values must be implemented ' \
            + u'in a subclass.'

    def new_ks_column_virtual_values(self, *args):
        raise NotImplementedError, \
            u'new_ks_column_virtual_values must be implemented ' \
            + u'in a subclass.'


    def set_environment(self, env):
        raise NotImplementedError, \
            u'set_environment must be implemented in a subclass.'